{extend name="index/index" /}

<!--main-->
{block name="main"}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="#">Home</a>
            </li>

            <li>
                <a href="/role">用户权限分配</a>
            </li>
            <li class="active">权限分配</li>
        </ul><!-- .breadcrumb -->

        <!--<div class="nav-search" id="nav-search">-->
            <!--<form class="form-search">-->
								<!--<span class="input-icon">-->
									<!--<input type="text" placeholder="Search ..." class="nav-search-input"-->
                                           <!--id="nav-search-input" autocomplete="off"/>-->
									<!--<i class="icon-search nav-search-icon"></i>-->
								<!--</span>-->
            <!--</form>-->
        <!--</div>&lt;!&ndash; #nav-search &ndash;&gt;-->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                用户
                <small>
                    <i class="icon-double-angle-right"></i>
                    权限列表（查看用户权限、更改用户角色）
                </small>
            </h1>
        </div><!-- /.page-header -->

        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->

                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-responsive">
                            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center">
                                        <label>
                                            <input type="checkbox" class="ace"/>
                                            <span class="lbl"></span>
                                        </label>
                                    </th>
                                    <th>编号</th>
                                    <th>姓名</th>
                                    <th class="hidden-480">角色</th>

                                    <th>
                                        <i class=" hidden-480"></i>
                                        权限
                                    </th>
                                    <th class="hidden-480">状态</th>
                                    <th class="hidden-480">操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                {volist name="result" id="v" key="k" }
                                <!--tr-->


                                <tr>
                                    <td class="center">
                                        <label>
                                            <input type="checkbox" class="ace"/>
                                            <span class="lbl"></span>
                                        </label>
                                    </td>

                                    <td>
                                        <a href="#">{$v['id']}</a>
                                    </td>
                                    <td>{$v['uname']}</td>
                                    <td class="hidden-480">{$v['rname']}</td>
                                    <td> <a href="{:url('admin/role/action',['id'=>$v['id']])}">点击查看</a></td>

                                    <td class="hidden-480">
                                        <span class="label label-sm label-warning">
                                          {switch name="v.status"}
                                            {case value="0"} 禁用{/case}
                                            {case value="1"} 激活{/case}
                                            {/switch}
                                        </span>
                                    </td>

                                    <td>
                                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                            <a class="blue"  href="{:url('admin/role/action',['id'=>$v['id']])}"   >
                                                <i class="icon-zoom-in bigger-130"></i>
                                            </a>

                                            <a class="green show-btn"  data-toggle="modal" data-id="{$v['id']}"  data-target="#myModal">
                                                <i class="icon-pencil bigger-130"></i>
                                            </a>

                                            <a class="red del-btn" >
                                                <i class="icon-trash bigger-130"></i>
                                            </a>


                                        </div>

                                        <div class="visible-xs visible-sm hidden-md hidden-lg">
                                            <div class="inline position-relative">
                                                <button class="btn btn-minier btn-yellow dropdown-toggle"
                                                        data-toggle="dropdown">
                                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                                </button>

                                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
                                                    <li>
                                                        <a href="#" class="tooltip-info" data-rel="tooltip"
                                                           title="View">
														<span class="blue">
															<i class="icon-zoom-in bigger-120"></i>
														</span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a href="#" class="tooltip-success" data-rel="tooltip"
                                                           title="Edit">
														<span class="green">
															<i class="icon-edit bigger-120"></i>
														</span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a   class="tooltip-error " data-rel="tooltip"
                                                             title="Delete" >
    													<span class="red">
    														<i class="icon-trash bigger-120"></i>
    													</span>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <!--endtr-->
                                {/volist}

                                </tbody>
                            </table>

                        </div>
                    </div>
                </div>


                <!--编辑的模态框-->
                <div id="modal-table" class="modal fade" tabindex="-1">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header no-padding">

                                <div class="table-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                        <span class="white">&times;</span>
                                    </button>
                                    Results for "Latest Registered Domains
                                </div>
                            </div>

                            <div class="modal-body no-padding">
                                <table class="table table-striped table-bordered table-hover no-margin-bottom no-border-top">


                                    <!--<tbody>-->
                                    <!--<tr>-->
                                        <!--<td>-->
                                            <!--<a href="#">ace.com</a>-->
                                        <!--</td>-->
                                        <!--<td>$45</td>-->
                                        <!--<td>3,330</td>-->
                                        <!--<td>Feb 12</td>-->
                                    <!--</tr>-->

                                    <!--<tr>-->
                                        <!--<td>-->
                                            <!--<a href="#">base.com</a>-->
                                        <!--</td>-->
                                        <!--<td>$35</td>-->
                                        <!--<td>2,595</td>-->
                                        <!--<td>Feb 18</td>-->
                                    <!--</tr>-->

                                    <!--<tr>-->
                                        <!--<td>-->
                                            <!--<a href="#">max.com</a>-->
                                        <!--</td>-->
                                        <!--<td>$60</td>-->
                                        <!--<td>4,400</td>-->
                                        <!--<td>Mar 11</td>-->
                                    <!--</tr>-->

                                    <!--<tr>-->
                                        <!--<td>-->
                                            <!--<a href="#">best.com</a>-->
                                        <!--</td>-->
                                        <!--<td>$75</td>-->
                                        <!--<td>6,500</td>-->
                                        <!--<td>Apr 03</td>-->
                                    <!--</tr>-->

                                    <!--<tr>-->
                                        <!--<td>-->
                                            <!--<a href="#">pro.com</a>-->
                                        <!--</td>-->
                                        <!--<td>$55</td>-->
                                        <!--<td>4,250</td>-->
                                        <!--<td>Jan 21</td>-->
                                    <!--</tr>-->
                                    <!--</tbody>-->
                                </table>
                            </div>

                            <div class="modal-footer no-margin-top">
                                <button class="btn btn-sm btn-danger pull-left" data-dismiss="modal">
                                    <i class="icon-remove"></i>
                                    Close
                                </button>

                                <ul class="pagination pull-right no-margin">
                                    <li class="prev disabled">
                                        <a href="#">
                                            <i class="icon-double-angle-left"></i>
                                        </a>
                                    </li>

                                    <li class="active">
                                        <a href="#">1</a>
                                    </li>

                                    <li>
                                        <a href="#">2</a>
                                    </li>

                                    <li>
                                        <a href="#">3</a>
                                    </li>

                                    <li class="next">
                                        <a href="#">
                                            <i class="icon-double-angle-right"></i>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
                <!--END编辑的模态框-->

                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
</div><!-- /.main-content -->


</div><!-- /#ace-settings-container -->
</div><!-- /.main-container-inner -->

<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="icon-double-angle-up icon-only bigger-110"></i>
</a>
</div><!-- /.main-container -->

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-4">
                        <img  class="img-responsive icon" src="" width="150px">
                    </div>

                    <div class="col-md-8">
                        <table class="table table-hover table-bordered">
                            <tr>
                                <th>编号</th>
                                <th>姓名</th>
                                <th> 角色</th>
                                <th>权限</th>
                            </tr>

                            <tr>
                                <td id="td1"></td>
                                <td id="td2"></td>
                                <td id="td3"></td>
                                <td id="td4"></td>
                            </tr>


                        </table>


                        <form action="{:url('admin/role/up')}" method="get">
                            更新权限 <select id="select">
                                    </select>
                            <input id="ppp" type="hidden" name="num" value="root">
                            <input id="pppp" type="hidden" name="id" value="1">
                            <input type="submit" class=" btn-xs btn btn-info" value="确定">
                        </form>

                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- endModal -->



<!-- 查看的Modal -->
<div class="modal fade" id="myModa2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-4">
                        <img  class="img-responsive icon1" src="" width="150px">
                    </div>

                    <div class="col-md-8">
                        <table id="tab" class="table table-hover table-bordered">
                            <tr>
                                <th>姓名</th>
                                <th> 角色</th>
                                <th>权限</th>
                                <th>可访问的控制器</th>
                                <th>可访问的方法</th>
                            </tr>





                        </table>



                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- 查看的endModal -->

{/block}
<!-- basic scripts -->

<!--[if !IE]> -->

<script src="/static/admin/js/jquery.min.js"></script>

<!-- <![endif]-->

{block name="myjs" }
<!--[if IE]>
<script src="/static/admin/js/1.10.2/jquery.min.js"></script>
<![endif]-->

<!--[if !IE]> -->

<script type="text/javascript">
    window.jQuery || document.write("<script src='/static/admin/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
    window.jQuery || document.write("<script src='/static/admin/js/jquery-1.10.2.min.js'>" + "<" + "/script>");
</script>
<![endif]-->

<script type="text/javascript">
    if ("ontouchend" in document) document.write("<script src='/static/admin/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script src="/static/admin/js/bootstrap.min.js"></script>
<script src="/static/admin/js/typeahead-bs2.min.js"></script>

<!-- page specific plugin scripts -->

<script src="/static/admin/js/jquery.dataTables.min.js"></script>
<script src="/static/admin/js/jquery.dataTables.bootstrap.js"></script>

<!-- ace scripts -->

<script src="/static/admin/js/ace-elements.min.js"></script>
<script src="/static/admin/js/ace.min.js"></script>

<!-- inline scripts related to this page -->

<script type="text/javascript">

//    $('.p-btn').click(function(){
//        var p_id=$(this).attr('data-id');
//        pAjax(p_id);
//    });
//
//    function pAjax(id){
//        $.ajax({
//            type:'get',
//            dataType:'json',
//            url:'action/',
//            data:{id:id},
//            success:function(data) {
//
//                var table = document.getElementById('tab');
//                for (var i = 0; i < data[0]; i++) {
//            console.log(i);
//            var index.html = table.rows.length;
//            var tr = table.insertRow(index.html);
//            // 给tr添加列(单元格)并写入内容
//            tr.insertCell(0).innerHTML = id;
//            tr.insertCell(1).innerHTML = data[2];
//            tr.insertCell(2).innerHTML = data[3];
//            tr.insertCell(3).innerHTML = data[0][i].controller;
//            tr.insertCell(4).innerHTML = data[0][i].method;
//        }
//
//                },
//            error:function()
//            {
//            },
//        });
//    }

//


    $('.show-btn').click(function(){
        var show_id=$(this).attr('data-id');
        showAjax(show_id);
    });

    function showAjax(id){
        $.ajax({
            type:'get',
            dataType:'json',
            url:'role/'+id,
            success:function(data){

                if (data) {
                    $('h4').html('查无数据,可能权限不够哦~~~');
                }
                var obj=document.getElementById('select');
                obj.options.length=0;
                $('#pppp').val(id);
                for (var i = 0; i < data.role.length; i++) {
                    obj.options.add(new Option(data.role[i].name,data.role[i].name));
                }
                $(obj).change(function(){
                    var options=$("#select option:selected"); //获取选中的项
                   var text=options.val();
                    $('#ppp').val(text);
                })


                if(data.status){
                    $('h4').html(data.title);
                    td1.innerHTML=data.num;
                    td2.innerHTML=data.info[0].uname;
                    td3.innerHTML=data.info[0].rname;
                    td4.innerHTML='权限';
                    var str=data.info[0].icon;
                    var pic = str.replace(/'/g,"");
                    $('.icon').attr({'src':pic+"?flag="+Math.random()});
                }else{
                    $('h4').html(data.title);
//                    $('.icon').attr(data.src);
                }

            },
            error:function(){


            },
        });
    }



    $('.edit-btn').click(function(){
        var edit_id=$(this).attr('data-id');
            updateAjax(edit_id);
    })

    function updateAjax(id){

        $.ajax({
            type:'post',
            dataType:'json',
            url:'role/'+id,
            data:{_method:'PUT'},
            success:function(data){


//                if(data.status){
//                    toastr.success(data.info);
//                    tr.remove();
//                }else{
//                    toastr.error(data.info,'警告');
//                }
            },
            error:function(){


            },
        });
    }


    jQuery(function ($) {
        var oTable1 = $('#sample-table-2').dataTable({
            "aoColumns": [
                {"bSortable": false},
                null, null, null, null, null,
                {"bSortable": false}
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
    })

</script>
{/block}

<div style="display:none">
    <script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script>
</div>
</body>
</html>
